package com.xiaoyun.activiti02;


import org.activiti.engine.*;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;

import java.io.IOException;

/**
 * 单个流程实例挂起与激活
 */
public class SuspendProcessInstance2 {

    //Exception in thread "main" org.activiti.engine.ActivitiException:
    // Cannot complete a suspended task
    public static void main(String[] args) {
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

        TaskService taskService = processEngine.getTaskService();
        Task task = taskService.createTaskQuery()
                .processDefinitionKey("holiday")
                .taskAssignee("zhangsan")
                .singleResult();
        taskService.complete(task.getId());

        System.out.println(task.getId());

    }

//    //流程定义：15001激活
//    public static void main(String[] args) throws IOException {
//
//        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//
//        RuntimeService runtimeService = processEngine.getRuntimeService();
//
//        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
//                .processInstanceId("15001").singleResult();
//
//        //如果进程定义处于挂起状态，则返回true。
//        boolean b = processInstance.isSuspended();
//        String processInstanceId = processInstance.getId();
//        if (b) {
//            runtimeService.activateProcessInstanceById(processInstanceId);
//            System.out.println("流程定义：" + processInstanceId + "激活");
//        } else {
//            runtimeService.suspendProcessInstanceById(processInstanceId);
//            System.out.println("流程定义：" + processInstanceId + "挂起");
//        }
//    }
}
